<!--
 * @Descripttion: 
 * @version: 1.0
 * @Author: 任静
 * @Date: 2020-11-11 16:30:15
 * @LastEditors: 任静
 * @LastEditTime: 2020-11-12 20:36:26
-->
<template>
    <div class="message">
        <div class="messageHeader">
            消息
        </div>
        <div class="messageMain">
            <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
                <van-list
                    v-model="loading"
                    :finished="finished"
                    finished-text="没有更多了"
                    @load="onLoad"
                >
                    <van-cell v-for="item in list" :key="item" :title="item" />
                </van-list>
            </van-pull-refresh>
        </div>
    </div>
</template>
<script>
import {defineComponent,reactive,toRefs} from "vue"
export default defineComponent({
    setup(prop,context){
        let data = reactive({
            list: [],
            loading:false,
            finished:false,
            refreshing:false,
        })


    function onLoad(){
      setTimeout(() => {
        if (data.refreshing) {
          data.list = [];
          data.refreshing = false;
        }

        // for (let i = 0; i < 10; i++) {
        //   data.list.push(data.list.length + 1);
        // }
        data.loading = false;

        // if (data.list.length >= 40) {
        //   data.finished = true;
        // }
      }, 1000);
    }
    function onRefresh(){
      // 清空列表数据
      data.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      data.loading = true;
      onLoad();
    }

    return {
            ...toRefs(data),
            onLoad,
            onRefresh
        }
    }
});
</script>
<style lang="scss" scoped>
    .message{
        width: 100%;
        height: 100%;
        display: flex;
        overflow: hidden;
        flex-direction: column;
        font-size: 16px;
    }
    .messageHeader{
        width: 100%;
        height:50px;
        border-bottom: 1px solid #ccc;
        display: flex;
        justify-content: center;
        align-items: center;
        font-weight: bold;
    }
    .messageMain{
        flex:1;
        overflow: auto;
        .van-pull-refresh{
            width: 100% !important;
            height: 100% !important;
            // background:orangered;
        }
    }
</style>